﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Framework;

namespace NLBS.Validate
{
   public class ValidateHelper
    {

        /// <summary>
        /// 检测评论间隔时间
        /// </summary>
        public static void checkPostDuration()
        {
            //评论时间间隔判断
            if (GlobalData.FloodControl == DateTime.MinValue)
            {
                GlobalData.FloodControl = DateTime.Now;
            }
            else
            {
                TimeSpan ts = (DateTime.Now - GlobalData.FloodControl);

                if (ts.TotalSeconds < BlogInfo.Instance().MinPostDuration)
                {
                    GlobalData.FloodControl = DateTime.Now;
                    // Check if user is banned for Spam
                    throw new Exception("你太辛苦了，喝杯茶休息一下吧！ ");
                }
            }
        }

        /// <summary>
        /// 检测留言间隔时间
        /// </summary>
        public static void checkGBookPostDuration()
        {
            //评论时间间隔判断
            if (GlobalData.GBookFloodControl == DateTime.MinValue)
            {
                GlobalData.GBookFloodControl = DateTime.Now;
            }
            else
            {
                TimeSpan ts = (DateTime.Now - GlobalData.GBookFloodControl);

                if (ts.TotalSeconds < BlogInfo.Instance().MinPostDuration)
                {
                    GlobalData.GBookFloodControl = DateTime.Now;
                    // Check if user is banned for Spam
                    throw new Exception("你太辛苦了，喝杯茶休息一下吧！ ");
                }
            }
        }
    }
}
